<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container">
      <panel-group :panel-data="panelData" @handleSetLineChartData="handleSetLineChartData" />
      <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
        <line-chart :chart-data="lineChartData" />
      </el-row>
      <el-row :gutter="32">
        <el-col :xs="24" :sm="24" :lg="12">
          <div class="chart-wrapper">
            <pie-chart />
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="12">
          <div class="chart-wrapper">
            <pie-chart-age />
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import PanelGroup from './dashboard/PanelGroup'
import PieChart from '@/components/Echarts/PieChart'
import PieChartAge from '@/components/Echarts/PieChartAge'
import { queryDashboard } from '@/api/testDashboard'
import LineChart from '@/views/test/home/LineChart.vue'

const lineChartData = {
  xAxisData: [],
  X: [],
  name: '入组患者数量'
}
const panelData = {
  A: 1,
  B: 2,
  C: 3,
  D: 4
}
export default {
  name: 'Dashboard',
  components: {
    PanelGroup,
    LineChart,
    PieChart,
    PieChartAge
  },
  data() {
    return {
      lineChartData: lineChartData,
      panelData: panelData
    }
  },
  created() {
    queryDashboard().then(res => {
      this.lineChartData.X = res.lineChartData
      this.lineChartData.xAxisData = res.xAxisData
      this.panelData.A = res.patientCount
      this.panelData.B = res.newAddCount
      this.panelData.C = res.completeCount
      this.panelData.D = res.lackCount
    })
  },
  methods: {
    handleSetLineChartData(type) {
      queryDashboard().then(res => {
        this.lineChartData.X = res.lineChartData
        this.lineChartData.xAxisData = res.xAxisData
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }

  @media (max-width:1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }
</style>
